#include "statemanager.h"
#include "OgreStringConverter.h"
 
StateManager::StateManager() {
    m_state = STARTUP;
}
 
StateManager::~StateManager() {
}
 
StateManagerState StateManager::getCurrentState() {
    return m_state;
}
 
// for the sake of clarity, I am not using actual thread synchronization 
// objects to serialize access to this resource. You would want to protect
// this block with a mutex or critical section, etc.
bool StateManager::lockState() {
    if (m_locked == false) {
 
        m_locked = true;
        return true;
    }
    else
        return false;
}
 
bool StateManager::unlockState() {
    if (m_locked == true) {
        m_locked = false;
        return true;
    }
    else
        return false;
}
 
bool StateManager::requestStateChange(StateManagerState newState) {
    if (m_state == STARTUP) {
        m_locked = false;
        m_state = newState;
 
        return true;
    }
 
    // this state cannot be changed once initiated
    if (m_state == SHUTDOWN) {
        return false;
    }
 
	if ((newState != STARTUP) && (newState != m_state)) {
        m_state = newState;
        return true;
    }
    else
        return false;
}
 
void StateManager::setFrameTime(float ms) {
    m_frame_time = ms;
}
